#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
struct sided{
    int point;
    int value;
};
vector<sided>side[200002];
bool cmp(sided a,sided b){
    return a.point<b.point;
}
int main(){
    int n,e;
    cin>>n>>e;
    for(int i=1;i<=e;i++){
        int a,b,w;
        cin>>a>>b>>w;
        sided c;
        c.point=b;
        c.value=w;
        side[a].push_back(c);
    }
    for(int i=0;i<n;i++){
        if(side[i].size())cout<<i<<":";
        else continue;
        sort(side[i].begin(),side[i].end(),cmp);
        for(int j=0;j<side[i].size();j++){
            cout<<"("<<i<<","<<side[i][j].point<<","<<side[i][j].value<<")";
        }
        cout<<endl;
    }
    return 0;
}